/
MonthsIterator.php
46 lines (37 loc) 路 1007 Bytes
/
MonthsIterator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<?php
declare(strict_types=1);
namespace Aeon\Calendar\Gregorian;
final class MonthsIterator extends \IteratorIterator
{
/**
* @param \Traversable<DateTime> $iterator
*/
private function __construct(\Traversable $iterator)
{
parent::__construct($iterator);
}
/**
* @psalm-suppress MixedArgumentTypeCoercion
*/
public static function fromDateTimeIterator(DateTimeIntervalIterator $iterator) : self
{
return new self($iterator);
}
public function current() : ?Month
{
/** @var null|DateTime|Month $current */
$current = parent::current();
if ($current === null) {
return null;
}
if ($current instanceof Month) {
return $current;
}
return $current->month();
}
public function reverse() : self
{
/** @phpstan-ignore-next-line */
return new self(new \ArrayIterator(\array_reverse(\iterator_to_array($this))));
}
}